package org.mikeliu.help;

import java.util.Formatter;
import java.util.Map;

import org.mikeliu.argument.Argument;
import org.mikeliu.argument.ArgumentType;

public class Generator {
    private Generator()
    {
        // This Class can not be constructed.
    }
    public static String help(String programName, String manualContent, Map<Argument, String> arguments) {
        StringBuilder helpContent = new StringBuilder();
        helpContent
        .append("Usage: ")
        .append(programName)
        .append("\n\n")
        .append(manualContent)
        .append("\n\n");
        for(Map.Entry<Argument, String> argument : arguments.entrySet()) {
            helpContent
            .append("    ")
            .append(
                Boolean.TRUE.equals((argument.getKey().getArgumentType().equals(ArgumentType.LONG))) ? "--" : "-"
            )
            .append(
                (argument.getKey().getArgumentString())
            )
            .append("    ")
            .append(argument.getValue())
            .append("\n");
        }
        return helpContent.toString();
    }

    public static String help(String programName, String manualContent, Map<Argument, String> arguments, String[] functions) {
        StringBuilder stringBuilder = new StringBuilder(help(programName, manualContent, arguments));
        stringBuilder.append("\n\nCurrently defined functions:\n");
        for (int i=0; i<functions.length; i++) {
            if(i!=0)stringBuilder.append(',');
            stringBuilder.append(functions[i]);
        }
        
        return stringBuilder.toString();
    }

    public static String version(String version, String build) {
        try (Formatter formatter = new Formatter()) {
            formatter.format("Massbox %s %s",version,build);
            return formatter.toString();
        }
    }
}
